<?
$sub_menu = "400200";
include_once("./_common.php");
$g4[title] = "카테고리 생성";
auth_check($auth[$sub_menu], "w");
include_once("./admin.head.php");

sql_query(" ALTER TABLE `g4_category` CHANGE `c_sort` `c_sort` INT( 10 ) NOT NULL  ", false);
sql_query(" ALTER TABLE `g4_category` ADD `c_show` CHAR( 1 ) NOT NULL DEFAULT '1' AFTER `c_sort` ", false);

$IDX = $_GET['IDX'] ? $_GET['IDX'] : "";

if($w=="u")
{
	$SQL = "SELECT *
						FROM " . $g4['category_table'] . "
							WHERE idx = '" . $IDX . "'
								LIMIT 1";

	$DATA = sql_fetch($SQL);

	$r_code = $DATA['c_code'];
}

if($r_code=="")
{
	$r_code = "C".time().rand(11,99);
}

?>
<form name="create_category" method="post" action="category_update.php">
<input type="hidden" name="w" value="<?=$w?>">
<input type="hidden" name="IDX" value="<?=$IDX?>">
<input type="hidden" name="c_depth" value="<?=$c_depth?>">
<input type="hidden" name="c_pcode" value="<?=$c_code?>">

<table cellpadding="0" cellspacing="1" border="0">
<?if(!$c_code || $c_code==""){?>
<input type="hidden" name="gubun" value="">
	<tr>
		<td colspan="3" class="bgcol1 bold">카테고리 생성</td>
	</tr>
	<tr>
		<td width="120" class="bgcol1 bold">카테고리명</td>
		<td>
		<input type="text" name="c_code" id="c_code" style="width:120px" class="ed" readonly value="<?=$r_code?>" />
		<input type="text" name="c_name" style="width:200px" class="ed" value="<?=$DATA[c_name]?>" />
		</td>
	</tr>
	<tr>
		<td width="120" class="bgcol1 bold">보이기여부</td>
		<td>
			<select name="c_show">
				<option value="1" <?php if($DATA['c_show'] == "1") echo " selected='selected' " ?> >보이기</option>
				<option value="2" <?php if($DATA['c_show'] == "2") echo " selected='selected' " ?> >감추기</option>
			</select>
		</td>
	</tr>
	<tr>
		<td width="120" class="bgcol1 bold">출력순서</td>
		<td>
		<input type="text" name="c_sort" style="width:200px" class="ed" value="<?=$DATA[c_sort]?>">
		</td>
	</tr>
	<tr>
		<td colspan="2" width="40"><button class="btn1" style="height:20px;height:40xp" onclick="CheckSend();">등록</button></td>
	</tr>
</form>
<?}else{?>
<input type="hidden" name="gubun" value="Two">
	<tr>
		<td width="120" class="bgcol1 bold">
		2차카테고리명
		<span style="font-weight:bold;cursor:pointer" onclick="CnameAdd()">+</span>
		</td>
		<td valign="top">
		<table cellpadding="0" cellspacing="0" border="0" id="Cname">
			<tr>
				<td><input type="text" name="c_name[]" style="width:200px" class="ed" value="<?=$DATA[c_name]?>"></td>
				<td></td>
			</tr>
		</table>
		</td>
	</tr>
	<tr>
		<td colspan="2" width="40"><button class="btn1" style="height:20px;height:40xp" onclick="CheckSend();">등록</button></td>
	</tr>
<?}?>
</table>
</form>
<script>
function CnameAdd()
{
	var TARGET = "Cname";
	var objTbl;
	var objRow;
	var objCell;
	if (document.getElementById)
	{
		objTbl = document.getElementById(TARGET);
	}
	else
	{
		objTbl = document.all[TARGET];
	}

	var NewRow = objTbl.rows.length;

	objRow = objTbl.insertRow(NewRow);
	objRow.id = NewRow;
	objCell1 = objRow.insertCell(0);
	objCell1.innerHTML = "<input type='text' style='width:200px' class='ed' name='c_name[]' value=''>";
	objCell2 = objRow.insertCell(1);
	objCell2.innerHTML = "<button class='btn1' onclick='CnameSub(this)'>취소</button>";
}

function CnameSub(btn)
{
	var TARGET = "Cname";
	var objTbl = document.all(TARGET);
	var delRow = btn.parentNode.parentNode.rowIndex;
	objTbl.deleteRow(delRow);
}


function CheckSend()
{
	var frm = document.create_category;
//	if(frm.c_name=="")
//	{
//		alert("카테고리명을 입력하세요.");
//		frm.c_name.focus();
//	}
//	else
//	{
		frm.submit();
//	}
}
</script>
<?
include_once ("./admin.tail.php");
?>